<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>《系统工程》精品资源共享课——教学课件</title>
	<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="../css/common.css">
	<style type="text/css">
		main {
			width:95%;
			margin:0 auto;
			margin-bottom: 50px;
			padding-bottom: 70px;
		}
		#catalog {
			margin:10px;
			background-color: white;
			border-radius: 8px;
			min-width:200px;
			padding:  0;
			min-height: 530px;
			overflow-y: scroll;
		}
		#catalog>ul>li {
			padding:25px 0px 20px 0px;
			cursor: pointer;
			font-size:16px;
			border-radius: 4px;
			margin:0;
		}
		#catalog ul li a:hover {
			background-color:#504D4D;
			width: 100%;
			color:white;
		}
		#catalog .dropdown-menu {
			position:relative;
			width:100%;
			top:20px;
			display: none;
		}
		#catalog li {
			width:100%;
			text-align: center;
		}
		#catalog .dropdown-menu li a:nth-child(1) {
			width:100%;
			margin-top: -5px;
			padding: 10px;
		}
		.li-click {
			background-color:#2C2B2B;
			color:white;
		}
		
		#coursesContent {
			border-radius: 8px;
			background-color: white;
			/*box-sizing:border-box;*/
			padding:20px 30px; 
			margin:10px 20px;
			min-width:600px;
			height:530px;
			overflow-y: scroll;
		}
		
		#video video {
			width:90%;
			margin: 15px auto;
		}

		#video select {
			width:50%;
			margin: 0 15px;
			display: inline-block;
		}

		#video ,#ppt,#homework {
			margin-top:15px;
			font-size: 18px;
			padding-bottom: 10px;
			border-bottom:1px solid #7F7F7F;
		}

		#video h4,#ppt h4,#homework h4 {
			color:#504D4D;
		}


		#video span,#ppt span,#homework span {
			display: inline-block;
			margin-right:10px; 
		}

		#homework a {
			display: block;
			padding-bottom: 10px;
		}

		main>.rows{
			width:90%;
			margin:0 auto;
		}

		#message , #Comment  {
			width:90%;
			margin:0 auto;
			padding:20px;
		}
		.textarea .btn-groups {
			width:15%;
		}
		
		.messageList{
			margin-top:50px;
			width:95%;
			
			
		}
		.messageList .list-left{
			padding:10px 20px;
		}

		.tupian{
			width:50px;
			height:50px;
			border-radius: 50%;
			border:2px solid #bfbfbf;

		}

		.messages{
			background-color: white;
			border-radius: 5px;
			padding-bottom:30px;
		}

		.messageList figure h4{
			display: inline-block;
			padding-top:15px;
			margin:0;
			
		}
		
		.messageList figure p{
			padding:10px;
			padding-left: 0;
			word-break: break-word;
		}

		.messageList figure.message{
			margin:20px 0;
			position:relative;
		}

		.messageList figure.comment{
			padding-bottom:20px;
		}

		.messageList .comments{
			border-left:2px solid #bfbfbf;
			float:right;
			width:90%;
			margin:10px 0 0 0;
			
		}

		.messageList .messages:after{
			content:"";
			display:block;
			overflow: hidden;
			clear:both;
			visibility: hidden;
		}	

		.messageList .comment-icon img{
			width:20px;
			height:20px;
			margin-right:20px;
		}

		.messageList .comment-icon{
			padding:0px;
			position:absolute;
			left:9.2%;
			bottom:-30%;
			color:#808080;
			cursor: pointer;

		}

		.messageList .btn-groups a{
			margin-left:20px;
			cursor: pointer;
		}
		
		.reply{
			padding-left:10px;
		}
		.reply span{
			padding-left:10px;
		}

	</style>
</head>
<body>
	<div id="top">
		<img src="../image/huanonglogo.png" class="logo">
		<ul>
			<li class="userInfo hidden"><a href="userInformation.html">个人信息</a></li>
			<li><span id="user"></span></li>
			<li class="logout hidden"><a href="login.html">退出</a></li>
			<li id="login" class="login"><a href="login.html"><img src="../image/user.png"><span>登录</span></a></li>
		</ul>
	</div>
	<nav>
		<ul class="rows">
			<li class="col-md-2 col-lg-2"><a href="../index.html">首页</a></li>
			<li class="dropdown col-md-2 col-lg-2">
				<a href="#"  data-toggle="dropdown" class="dropdown-toggle">课程概要<span class="glyphicon glyphicon-chevron-down"></span></a>
				<ul class="dropdown-menu">
					<li><a href="primaryResource.html">教学大纲</a></li>
					<li><a href="primaryResource.html">教学日历</a></li>
					<li><a href="primaryResource.html">教学教材</a></li>
					<li><a href="primaryResource.html">参考资料</a></li>
					<li><a href="primaryResource.html">重点难点</a></li>
				</ul>
			</li>
			<li class="dropdown col-md-2 col-lg-2">
				<a href="#"  data-toggle="dropdown" class="dropdown-toggle">课程资源<span class="glyphicon glyphicon-chevron-down"></span></a>
				<ul class="dropdown-menu">
					<li><a href="video.html">教学视频</a></li>
					<li><a href="ppt.html">教学课件</a></li>
					<li><a href="homework.html">作业</a></li>
				</ul>
			</li>
			<li class="col-md-2 col-lg-2"><a href="courses.html">课程内容</a></li>
			<li class="col-md-2 col-lg-2"><a href="expandingResource.html">拓展资源</a></li>
			<li class="col-md-2 hidden teacher_li"><a href="teacherCourseManagement.html">课程管理</a></li>
		</ul>

	</nav>
	<main>
		<div class="rows">
			<section id="catalog" class="col-md-3 col-xs-6 col-lg-3">
				<ul>
					<!-- <li class="li-click dropdown">
						第1章 系统工程概述
						<span class="glyphicon glyphicon-chevron-down"></span>
						<ul class="dropdown-menu">
							<li class=""><a href="#video-s">视频</a></li>
							<li class=""><a href="#ppt">ppt</a></li>
							<li class=""><a href="#hw">作业</a></li>
						</ul>
					</li>
					<li class="dropdown">
						第2章 系统工程方法论<span class="glyphicon glyphicon-chevron-down"></span>
					</li>
					<li class="dropdown">第3章 系统模型与模型化</li>
					<li class="dropdown">第4章 系统仿真及系统动力学方法</li>
					<li class="dropdown">第5章 系统评价方法</li>
					<li class="dropdown">第6章 决策分析方法</li>
					<li class="dropdown">第7章 系统工程应用实例</li> -->
				</ul>
			</section>
			<section id="coursesContent" class="col-md-9 col-xs-6 col-lg-8">
				<section id="video">
					<!-- <select id="videoSelect" class="input form-control"></select> -->
					<!-- <video width="650px" height="400px" controlssrc="" type="video/mp4"></video> -->
				</section>
				<section id="ppt" >
					<!-- <a class="firstPpt" href=""><img src="../image/xiazai.png">下载</a> -->
				</section>
				<section id="homework">
					<!-- <a href=""><img src="../image/xiazai.png">下载</a> -->
				</section>
			</section>
		</div>
		<div id="message">
			<h3>Messages</h3>
			<div class="textarea">
				<input class="hidden" name="type"/><!-- 类型：message/comment -->
				<input class="hidden" name="operationType"/><!-- 类型：add/edit -->
				<input class="hidden" name="id"/><!-- id：msId/commentId -->
				<input class="hidden" name="msId"/><!-- 查询评论所用的msId：msId -->
				<input class="hidden" name="replyName"/><!-- 所回复评论的发言者的name：replyName -->
				<input class="hidden" name="replyNickname"/><!-- 所回复评论的发言者的nickname：replyNickname -->
				<textarea id="textarea" placeholder="可以输入250个字……Say Something……" rows="7" cols="150" maxlength="250"></textarea>
				<div class="btn-groups pull-right">
					<button class="btn btn-default" onclick="resetTextarea()">取消</button>
					<button class="btn btn-primary btn-submit">提交</button>
				</div>
			</div>
			<div class="messageList">
				<!-- <div class="messages">
					<figure class="rows message">
						<div class="col-md-1 list-left">
							<img class="tupian" src="../image/student.png" >
							<h5>student</h5>
						</div>
						<div class="col-md-11 list-right">
							<h4>张三</h4>
							<p></p>
							<div class="btn-groups" >
								<span>发表时间</span>
								<a class="editMsg">修改</a>
								<a class="delMsg">删除</a>
							</div>
						</div>
						<div class="comment-icon">
							<span class="icon-circle-add hidden"><img src="../image/circle-add.png" >展开隐藏评论</span>
							<img src="../image/circle-minus.png" class="icon-circle-minus">
						</div>
					</figure>
					<div class="comments">
						<figure class="rows comment">
							<div class="col-md-1 list-left">
								<img class="tupian" src="../image/teacher.png" >
								<h5>teacher</h5>
							</div>
							<div class="col-md-11 list-right">
								<h4>张三</h4><h4 class="reply">answers<span class="replyName">李四</span></h4>
								<p></p>
								<div class="btn-groups" >
									<span>发表时间</span>
									<a class="editMsg">修改</a>
									<a class="delMsg">删除</a>
								</div>
							</div>
						</figure>
						<figure class="rows comment">
							<div class="col-md-1 list-left">
								<img class="tupian" src="../image/student.png" >
								<h5>student</h5>
							</div>
							<div class="col-md-11 list-right">
								<h4>李四</h4><h4 class="reply">answers<span class="replyName">张三</span></h4>
								<p></p>
								<div class="btn-groups" >
									<span>发表时间</span>
									<a class="">修改</a>
									<a class="delMsg">删除</a>
								</div>
							</div>
						</figure>
					</div>
				</div>
				-->
			</div>
		</div>
	</main>
	<footer>
		<p>版权所有：华南农业大学 数学与信息学院 软件学院</p>
	</footer>
	<script type="text/javascript" src="../js/jquery-3.2.1.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../js/common.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			var sectionList,sectionId="";
			getAllSection();
			isLogin();
			
		})

		$("#catalog>ul").on("click","li",function(ev) {
			var target=$(ev.target);
			target.removeClass('li-click').addClass('li-click');
			target.siblings().removeClass('li-click');
			$("#homework").empty();
			$("#video").empty();
			$("#ppt").empty();
			$("#video").append('<h4><span class="glyphicon glyphicon-facetime-video"></span>视频</h4>');
			$("#homework").append('<h4><span class="glyphicon glyphicon-file"></span>作业</h4>');
			$("#ppt").append('<h4><span class="glyphicon glyphicon-book"></span>PPT</h4>');
			var seId=target.attr('name');
			sectionId=target.attr('name');
			getAllMessages();
			for(var i=0;i<sectionList.length;i++) {
				if(sectionList[i].seId==seId) {
					let videoList=sectionList[i].video;
					let homeworkList=sectionList[i].homework;
					if(videoList.length!=0) {
						$("#video").append('<select id="videoSelect" class="input form-control"></select><button class="btn btn-info" onclick="showVideo()">选择视频</button>');
						for (let j = 0; j < videoList.length; j++)  {
							$("#videoSelect").append('<option value="'+seId+'-'+videoList[j].vId+'">'+videoList[j].vName+'</option>')
						}
						$("#video").append('<video width="650px" height="400px" controls src="../videos/'+videoList[0].vName+'.mp4" type="video/mp4"></video>');
					}else {
						$("#video").append('<a class="noVideo" href="">该章节没有视频</a>');
						
					}
					if(homeworkList.length!=0) {
						for (let j = 0; j <homeworkList.length; j++)  {
							$("#homework").append('<a href="'+homeworkList[j].hName+'.doc"><img src="../image/xiazai.png">'+homeworkList[j].hName+'<span class="pull-right">更新时间：'+dateFormatter(homeworkList[j].hModifytime)+'</span></a>');
						}
					}else {
						$("#homework").append('<a>该章节没有作业</a>');
					}
					$("#ppt").append('<a href="'+sectionList[i].sePpt+'.ppt"><img src="../image/xiazai.png">第'+sectionList[i].seSeq+'章 PPT 下载</a>');
				}
				
			}
		});

		function showVideo() {
			var vId=$("#videoSelect").val().slice(-1);
			var seId=$("#videoSelect").val().slice(0,1);
			for(var i=0;i<sectionList.length;i++) {
				if(sectionList[i].seId==seId) {
					let videoList=sectionList[i].video;
					for (var j = 0; j < videoList.length; j++)  {
						if(videoList[j].vId==vId) {
							$("#video video").attr("src","../videos/"+videoList[j].vName+".mp4");
						}
					}
					
				}	
			}

		}

		function getAllSection() {
			var sectionNum;
			$.ajax( {
				url: '/sectionController/queryAllSection',
				type: 'POST',
				success: function(data) {
					sectionList=data;
					sectionNum=data.length;
					$("#video").append('<h4><span class="glyphicon glyphicon-facetime-video"></span>视频</h4>');
					$("#homework").append('<h4><span class="glyphicon glyphicon-file"></span>作业</h4>');
					$("#ppt").append('<h4><span class="glyphicon glyphicon-book"></span>PPT</h4>');
					for(var i=0;i<sectionNum;i++) {
						let videoList=data[i].video;
						let homeworkList=data[i].homework;
						$("#catalog ul").append('<li name="'+data[i].seId+'" class="dropdown">第'+data[i].seSeq+'章 '+data[i].seName+'</li>');
						if(data[i].seSeq==1) {
							sectionId=data[i].seId;
							$("#catalog ul").find("li[name="+data[i].seId+"]").addClass('li-click');
							if(videoList.length!=0) {
								$("#video").append('<select id="videoSelect" class="input form-control"></select>');
								for (let j = 0; j < videoList.length; j++)  {
									$("#videoSelect").append('<option>'+videoList[j].vName+'</option>')
								}
								$("#video").append('<video width="650px" height="400px" controls src="../videos/'+videoList[0].vName+'.mp4" type="video/mp4"></video>');
							}else {
								$("#video").append('<a class="noVideo" href="">该章节没有视频</a>');
								
							}
							if(homeworkList.length!=0) {
								for (let j = 0; j <homeworkList.length; j++)  {
									$("#homework").append('<a href="../resource/'+homeworkList[j].hName+'.doc"><img src="../image/xiazai.png">'+homeworkList[j].hName+'<span class="pull-right">更新时间：'+dateFormatter(homeworkList[j].hModifytime)+'</span></a>');
								}
							}else {
								$("#homework").append('<a>该章节没有作业</a>');
							}
							$("#ppt").append('<a href="../ppt/'+data[i].sePpt+'.ppt"><img src="../image/xiazai.png">第'+data[i].seSeq+'章 PPT 下载</a>');
						}
					}
					getAllMessages();
				}
			});
		}
		
		$(".messageList").on('click','.icon-circle-minus', function(event) {
			$(this).parents('.messages').children('.comments').addClass('hidden');
			$(this).siblings('.icon-circle-add').removeClass('hidden');
			$(this).addClass('hidden');
		});
		
		$(".messageList").on('click','.icon-circle-add', function(event) {	
			$(this).parents('.messages').children('.comments').removeClass('hidden');
			$(this).siblings('.icon-circle-minus').removeClass('hidden');
			$(this).addClass('hidden');
		});

		function getAllMessages(){
			var commentList;
			var userId=sessionStorage.getItem("id");
			var userType=sessionStorage.getItem("role");
			msIdArr=[];
			$.ajax({
				url: '/messageController/queryMessagesBySeId',
				type: 'POST',
				contentType : "application/x-www-form-urlencoded",
				data: {seId: sectionId},
				cache:false,
				success:function(data){
					$(".messageList").empty();
					if(data.length==0){
						$(".messageList").append('<h4>该章节还没有留言………</h4>')
					}else{
						for(var i=0;i<data.length;i++){
							$('.messages[name='+data[i].msId+'] .comments').remove();
							$('.messages[name='+data[i].msId+'] .comment-icon').remove();
							$(".messageList").append('<div class="messages" name="'+data[i].msId+'"><figure class="rows message"></figure></div>');
							$('.messages[name='+data[i].msId+']').find('.message').append('<div class="col-md-1 list-left"><img class="tupian" src="../image/'+data[i].userType+'.png" ><h5>'+data[i].userType+'</h5></div>');
							$('.messages[name='+data[i].msId+']').find('.message').append('<div class="col-md-11 list-right">'
								+'<h4>'+data[i].mNickname+'('+data[i].mName+')</h4>'
								+'<p class="messageContent">'+data[i].msContent+'</p>'
								+'<div class="btn-groups">'
								+'<span class="releaseTime">'+dateFormatter(data[i].msReleasetime)+'</span>'
								+'<a class="replyMsg">回复</a><a class="editMsg hidden">修改</a><a class="delMsg hidden">删除</a>'
								+'</div></div>');
							if(data[i].userId==userId&&data[i].userType==userType){
								$('.messages[name='+data[i].msId+']').find('.editMsg').removeClass('hidden');
								$('.messages[name='+data[i].msId+']').find('.delMsg').removeClass('hidden');
							}
							commentList=data[i].comment;
							if(commentList.length!=0){
								$('.messages[name='+data[i].msId+']').find('.message').append('<div class="comment-icon">'
									+'<span class="icon-circle-add hidden"><img src="../image/circle-add.png">展开隐藏评论</span>'
									+'<img src="../image/circle-minus.png" class="icon-circle-minus">'
									+'</div>');
								$('.messages[name='+data[i].msId+']').append('<div class="comments"></div>');
								for(var j=0;j<commentList.length;j++){
									$('.messages[name='+data[i].msId+']').find('.comments').append('<figure class="rows comment" name="'+commentList[j].commentId+'"></figure>');
									$('.comment[name='+commentList[j].commentId+']').append('<div class="col-md-1 list-left">'
										+'<img class="tupian" src="../image/'+commentList[j].commentUserType+'.png" >'
										+'<h5>'+commentList[j].commentUserType+'</h5>'
										+'</div>');
									$('.comment[name='+commentList[j].commentId+']').append('<div class="col-md-11 list-right">'
										+'<h4 class="replyName">'+commentList[j].cNickname+'('+commentList[j].cName+')</h4><h4 class="reply hidden">回复<span class="replyName">'+commentList[j].replyNickname+'('+commentList[j].replyName+')</span></h4>'
										+'<p class="commentContent">'+commentList[j].commentContent+'</p>'
										+'<div class="btn-groups" >'
										+'<span class="releaseTime">'+dateFormatter(commentList[j].commentReleasetime)+'</span>'
										+'<a class="replyComment">回复</a><a class="editComment hidden">修改</a><a class="delComment hidden">删除</a>'
										+'</div></div>');
									if(commentList[j].replyId!=null){
										$('.comment[name='+commentList[j].commentId+']').find('.reply').removeClass('hidden');
									}
									if(commentList[j].commentUserId==userId&&commentList[j].commentUserType==userType){
										$('.comment[name='+commentList[j].commentId+']').find('.editComment').removeClass('hidden');
										$('.comment[name='+commentList[j].commentId+']').find('.delComment').removeClass('hidden');
									}

								}
							}
						}

					}
				}
			});
			
		}

		function dateFormatter(dateparams){
			let date=new Date(dateparams);
			return date.getFullYear() + '-' +(date.getMonth()+1) + "-" + date.getDate() + " " +date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
		}

		$(".messageList").on('click','.delComment', function(event) {	
			var id=$(this).parents(".comment").attr('name');
			var msId=$(this).parents(".messages").attr('name');
			del("comment",id,msId);
		});

		$(".messageList").on('click','.delMsg', function(event) {	
			var id=$(this).parents(".messages").attr('name');
			del("message",id,null);
		});

		$(".messageList").on('click','.editComment', function(event) {	
			resetTextarea();
			var id=$(this).parents(".comment").attr('name');
			var msId=$(this).parents(".messages").attr('name');
			var content=$(this).parents(".comment").find('p.commentContent').html();
			$("#textarea").val(content);
			$(".textarea input[name='type']").val("comment");
			$(".textarea input[name='operationType']").val("edit");
			$(".textarea input[name='id']").val(id);
			$(".textarea input[name='msId']").val(msId);
			goToTextarea();
		});

		$(".messageList").on('click','.editMsg', function(event) {	
			resetTextarea();
			var id=$(this).parents(".messages").attr('name');
			var content=$(this).parents(".messages").find('p.messageContent').html();
			$("#textarea").val(content);
			$(".textarea input[name='type']").val("message");
			$(".textarea input[name='operationType']").val("edit");
			$(".textarea input[name='id']").val(id);
			goToTextarea();
		});

		$(".messageList").on('click','.replyComment', function(event) {	
			if(!isLogin()){
				if(confirm("留言板功能要登录才能使用！\n是否现在登录？")){
					window.location.href="login.html";
				}else{
					event.preventDefault();
				}
			}else{
				resetTextarea();
				var id=$(this).parents(".comment").attr('name');
				var name_nickname=$(this).parents(".comment").find('h4.replyName').html();
				var name_end_idx=name_nickname.indexOf('(');
				var replyNickname=name_nickname.slice(0,name_end_idx);
				var replyName=name_nickname.slice(name_end_idx+1,-1);
				$(".textarea input[name='type']").val("comment");
				$(".textarea input[name='operationType']").val("reply");
				$(".textarea input[name='id']").val(id);
				var msId=$(this).parents(".messages").attr('name');
				$(".textarea input[name='msId']").val(msId);
				$(".textarea input[name='replyName']").val(replyName);
				$(".textarea input[name='replyNickname']").val(replyNickname);
				goToTextarea();
			}
			
		});

		$(".messageList").on('click','.replyMsg', function(event) {	
			if(!isLogin()){
				if(confirm("留言板功能要登录才能使用！\n是否现在登录？")){
					window.location.href="login.html";
				}else{
					event.preventDefault();
				}
			}else{
				resetTextarea();
				var id=$(this).parents(".messages").attr('name');
				$(".textarea input[name='type']").val("message");
				$(".textarea input[name='operationType']").val("reply");
				$(".textarea input[name='id']").val(id);
				$(".textarea input[name='msId']").val(id);
				goToTextarea();
			}
			
		});

		function del(type,id,msId){
			var url="";
			if(type=="message"){
				url="/messageController/delMessage";
			}else if(type=="comment"){
				url="/commentController/delComment";
			}
			if(confirm("确定删除该"+type+"吗？")){
				$.ajax({
					url: url,
					type: 'POST',
					data: {id: id},
					success:function(data){
						if(data==1){
							alert("删除"+type+"成功");
						}else{
							alert("删除失败！");
						}
						getAllMessages();
						if(type=="comment"){
							getCommentByMsId(msId);
						}
					}
				});
			}
		}

		$(".textarea .btn-submit").click(function(){
			var type=$(".textarea input[name='type']").val();
			var operation=$(".textarea input[name='operationType']").val();
			var id=$(".textarea input[name='id']").val();
			var msId=$(".textarea input[name='msId']").val();
			var contents=$("#textarea").val();
			var url="";
			var params;

			if(type=="message"&&operation=="edit"){
				url="/messageController/editMessage";
				params={};
				params.id=id;
				params.content=contents;
			}else if(type=="message"&&operation=="reply"){
				url="/commentController/addComment";
				params={};
				params.msId=id;
				params.userId=sessionStorage.getItem("id");
				params.userType=sessionStorage.getItem("role");
				params.content=contents;
				params.replyId=null;
			}else if(type=="comment"&&operation=="edit"){
				url="/commentController/editComment";
				params={};
				params.id=id;
				params.content=contents;
			}else if(type=="comment"&&operation=="reply"){
				url="/commentController/addComment";
				params={};
				params.replyId=id;
				params.msId=msId;
				params.content=contents;
				params.userId=sessionStorage.getItem("id");
				params.userType=sessionStorage.getItem("role");
				params.replyName=$(".textarea input[name='replyName']").val();
				params.replyNickname=$(".textarea input[name='replyNickname']").val();
			}else{
				url="/messageController/addMessage";
				params={};
				params.content=contents;
				params.seId=sectionId;
				params.userId=sessionStorage.getItem("id");
				params.userType=sessionStorage.getItem("role");
			}
			var startIdx=url.lastIndexOf('/');
			var flag=false;
			if(url.slice(startIdx+1).search('Comment')!=-1){
				flag=true;
			}
			$.ajax({
				url: url,
				type: 'POST',
				contentType : "application/json;charset=utf-8",
				data: JSON.stringify(params),
				success:function(data){
					if(data==1){
						alert("操作成功");
						$("#textarea").val("");
					}else{
						alert("操作失败");
					}
					getAllMessages();
					if(flag){
						getCommentByMsId(msId);
					}
					resetTextarea();
				}
			});
			
		})

		function goToTextarea(){
			$("#textarea").focus();
			var top=$("#textarea").offset().top-100;
			$("html,body").animate({scrollTop: top},'slow');
		}

		function resetTextarea(){
			$("#textarea").val("");
			$(".textarea input[name='type']").val("");
			$(".textarea input[name='operationType']").val("");
			$(".textarea input[name='id']").val("");
			$(".textarea input[name='msId']").val("");
			$(".textarea input[name='replyName']").val("");
			$(".textarea input[name='replyNickname']").val("");
		}

		function getCommentByMsId(msId){
			var userId=sessionStorage.getItem("id");
			var userType=sessionStorage.getItem("role");
			var userName=sessionStorage.getItem("name");
			var userName=sessionStorage.getItem("nickname");
			var role=sessionStorage.getItem("role");
			$.ajax({
				url: '/commentController/queryCommentBymsId',
				type: 'POST',
				contentType : "application/x-www-form-urlencoded",
				data: {msId: msId},
				cache:false,
				success: function(data){
					$('.messageList').find('.messages[name='+msId+']').find('.comments').remove();
					if(data.length!=0){
						$('.messages[name='+msId+']').append('<div class="comments"></div>');
					}
					for(var i=0;i<data.length;i++){
						$('.messages[name='+msId+']').find('.comments').append('<figure class="rows comment" name="'+data[i].commentId+'"></figure>');
						$('.comment[name='+data[i].commentId+']').append('<div class="col-md-1 list-left">'
							+'<img class="tupian" src="../image/'+data[i].commentUserType+'.png" >'
							+'<h5>'+data[i].commentUserType+'</h5>'
							+'</div>');
						$('.comment[name='+data[i].commentId+']').append('<div class="col-md-11 list-right">'
							+'<h4 class="replyName">'+data[i].cNickname+'('+data[i].cName+')</h4><h4 class="reply hidden">回复<span class="replyName">'+data[i].replyNickname+'('+data[i].replyName+')</span></h4>'
							+'<p class="commentContent">'+data[i].commentContent+'</p>'
							+'<div class="btn-groups" >'
							+'<span class="releaseTime">'+dateFormatter(data[i].commentReleasetime)+'</span>'
							+'<a class="replyComment">回复</a><a class="editComment hidden">修改</a><a class="delComment hidden">删除</a>'
							+'</div></div>');
						if(data[i].replyId!=null){
							$('.comment[name='+data[i].commentId+']').find('.reply').removeClass('hidden');
						}
						if(data[i].commentUserId==userId&&data[i].commentUserType==userType){
							$('.comment[name='+data[i].commentId+']').find('.editComment').removeClass('hidden');
							$('.comment[name='+data[i].commentId+']').find('.delComment').removeClass('hidden');
						}
					}
				}
			});
			
		}

		function isLogin(){
			var id=sessionStorage.getItem("id");
			if(id==null){
				$(".textarea .btn-submit").attr("disabled",true);
				return false;
			}else{
				$(".textarea .btn-submit").attr("disabled",false);
				return true;
			}

		}
	</script>
</body>
</html>